package com.gz.logistics.library.listener;

import com.gz.logistics.library.pojo.SumOfMoney;
import com.gz.logistics.library.pojo.WillOutStorageAassemble;
import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * author wanner1991
 */
public abstract class GetSumOfMoneyListener extends BaseListener {
    private String TAG = GetSumOfMoneyListener.class.getSimpleName();

    public GetSumOfMoneyListener(RequestCode requestCode) {
        super(requestCode);
    }

    protected GetSumOfMoneyListener() {
    }
    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_STATUS);
            String msg = response.getString(Constants.REQ_MSG);
            switch(status){
                case Constants.REQ_OK:
                    JSONObject jsonObject = response.getJSONObject(Constants.REQ_RESULT);
                    onResponseSuccess(SumOfMoney.parse(jsonObject));
                    break;
                case Constants.REQ_NO_ASSEMBLES:
                    onNoConditionAssembles();
                    break;
                default:
                    onResponseFailed();
                    break;
            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }

    /**
     * 没有满足条件的预出库单
     */
    public abstract void onNoConditionAssembles();
    public abstract void onResponseSuccess(SumOfMoney moneys);
    @Override
    public void onFailure(int statusCode,
                          Header[] headers,
                          Throwable throwable,
                          JSONObject errorResponse) {
        CrashHandler.e(throwable);
        CrashHandler.i(TAG,"onFailure"+"发生异常");
        onResponseFailed();
    }

    @Override
    public void onOffline() {

    }

    @Override
    public void onNoMoreData() {

    }
}
